echo "docker环境下运行Web应用"

app=$1
full_img_ver=$2
ver=$3

if [ -z "$full_img_ver" ]; then
 echo "start-web.sh    应用名   完整的镜像名:版本号"
 echo "参数: $app,$full_img_ver"
 exit 1;
fi

set -eo pipefail

SCRIPTDIR=$(cd $(dirname "${BASH_SOURCE[0]}") >/dev/null && pwd)
cd $SCRIPTDIR

docker pull $full_img_ver

echo "正在启动 $app ..."

docker pull $full_img_ver


rm -rf docker-data && mkdir -p docker-data

docker save -o docker-data/docker-data.tar $full_img_ver

tar -xvf docker-data/docker-data.tar -C docker-data

cat docker-data/manifest.json | sed "s|\"|\n|g" | grep tar | cut -d '/' -f 1  | while read line; do
   tar -xvf docker-data/$line/layer.tar -C docker-data > /dev/null
done

rm -rf web/$app
mv docker-data/app  web/$app

echo "准备部署 $app"

web/run-ng.sh

